<?php

namespace App\Http\Resources;

use App\model\panyuan\UserShenheLog;
use App\UserShenhe;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Carbon;

class UserShenheCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'code'=>0,
            'data'=>$this->collection->map(function ($item){
                return [
                  'id'=>$item->id,
                  'title'=>$item->title,
                  'type_desc'=>UserShenhe::$typeMap[$item->type],
                  'type'=>$item->type,

                  'created_at'=>Carbon::parse(UserShenhe::where('code','=',$item->code)->orderBy('id','asc')->first()->created_at)->toDateString(),
                  'status'=>$item->status,
                  'updated_at'=>  Carbon::parse($item->updated_at)->format("Y年m月d日"),
                ];
            })
            ];
    }
}
